package com.lizhao.win007com.info.webapi.mapper;

import com.lizhao.win007com.commons.pojo.info.model.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InfoMapper {
    //获取监控表数据
//    @Select("SELECT * FROM `monitor` WHERE matchdatetime>=CURRENT_DATE ORDER BY id")
    @Select("SELECT * FROM `monitor-avg` ORDER BY matchdatetime;")
    List<MonitorAvgInfo> findMonitor();

    @Select("SELECT * FROM `monitor-easy` ORDER BY matchdatetime;")
    List<MonitorEasyInfo> findEasyMonitor();

    // 通过pageid获取平赔简易版数据
    @Select("SELECT * FROM `monitor-easy` WHERE pageid=#{pageid}")
    MonitorEasyInfo findEasyInfoByPageId(Integer pageid);

    // 通过pageid获取开盘赔型总数
    @Select("SELECT SUM(total) total FROM `monitor-easy-total` WHERE ttype=${ttype} AND pageid=${pageid};")
    MonitorPInfo findEasyPByPageIdAndTtype(@Param("pageid") Integer pageid, @Param("ttype") Integer ttype);

    //获取公司信息
    @Select("SELECT * FROM `companyinfo` ORDER BY companyid")
    List<CompanyInfo> findAllCompanyInfo();

    //全胜率数据
    @Select("SELECT * FROM `${table}` WHERE leagueid=${leagueid} ORDER BY ${ratetag} DESC LIMIT 130")
    List<RateInfo> findFullRateInfo(@Param("table") String table, @Param("leagueid") Integer leagueid,
                                   @Param("ratetag") String ratetag);

    //从当前胜率表获取胜率
    @Select("SELECT * FROM `leaguematch-rate-abs-current` WHERE leagueid=${leagueid} AND relation='${relation}' " +
            "AND ${ratetag} >= 75 AND companyid1<companyid2 ORDER BY ${ratetag} DESC;")
    List<RateInfo> findRateByLeagueIdAndRelationAndRateTag(@Param("leagueid") Integer leagueid,
                                                           @Param("relation") String relation,
                                                           @Param("ratetag") String ratetag);

    //获取联赛配置信息
    @Select("SELECT * FROM `leagueinfo` ORDER BY leagueid;")
    List<LeagueInfo> findAllLeagueInfo();

    //获取开放的联赛赛事类型
    @Select("SELECT * FROM `leagueInfo` WHERE enable=1 AND iscollect=1 ORDER BY leagueid;")
    List<LeagueInfo> findOpenLeagueInfo();

    //获取开放的杯赛赛事类型
    @Select("SELECT * FROM `cupInfo` WHERE enable=1 AND iscollect=1 ORDER BY cupid;")
    List<CupInfo> findOpenCupInfo();

    //获取杯赛配置
    @Select("SELECT * FROM `cupinfo` ORDER BY cupid ASC;")
    List<CupInfo> findAllCupInfo();

    //通过leagueid获取联赛信息
    @Select("SELECT * FROM `leagueinfo` WHERE leagueid=#{leagueid};")
    LeagueInfo findLeagueInfoByLeagueid(Integer leagueid);

    //获取配置模块信息
    @Select("SELECT * FROM `typeinfo`;")
    List<TypeInfo> findAllTypeInfo();

    //获取配置python生成文件的信息
    @Select("SELECT * FROM `config`;")
    List<ConfigInfo> findConfigInfo();

    //修改配置路径
    @Update("UPDATE `config` SET path=#{path},sleep=#{sleep} WHERE id=1;")
    Integer updateConfig( @Param("path") String path,@Param("sleep") Integer sleep);

    //修改入库配置
    @Update("UPDATE `${table}` SET ${field}=#{value} WHERE id=#{id};")
    Integer updateInfo(@Param("table") String table,@Param("id") Integer id,
                       @Param("field") String field,@Param("value") String value);

    //清空表
    @Update("TRUNCATE TABLE `${table}`;")
    void truncateByTable(String table);

    //通过type从odds表获取所有盘口
    @Select("SELECT * FROM `odds` WHERE type=#{type} GROUP BY odds ORDER BY odds ASC;")
    List<Odds> findOddsByType(String type);

    //添加盘口信息到odds表
    @Insert("INSERT INTO `odds` VALUES (NULL,#{type},#{season},#{odds});")
    void insertOdds(Odds odds);
}
